﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef MathType_h__
#define MathType_h__

#include <DirectXMath.h>
#include <DirectXColors.h>
#include <d2d1.h>
#include "../utility/MacroTool.h"

namespace SkyEngine2d
{
	
	/*!
	 \brief 2D向量
	 \details
	*/
	class SGE_API Vector2
		:public DirectX::XMFLOAT2
	{
	public:
	
		//! 默认构造
		Vector2();
	
		//! 参数构造
		/*!
		\param float x
		\param float y
		*/
		Vector2(float x, float y)
			:DirectX::XMFLOAT2(x, y) {}
	
		//! 参数构造
		/*!
		\param DirectX::XMVECTOR v
		\return
		*/
		Vector2(DirectX::XMVECTOR v);
	
		//! 赋值构造
		Vector2(const Vector2& v);
	
		//! 析构
		~Vector2();
	
		//! 类型转换
		operator DirectX::XMVECTOR() const;
	
		//! 类型转换
		operator D2D_POINT_2F()const;
	
		//重载运算符
		bool operator == (const  Vector2& v)const;
		bool operator != (const  Vector2& v)const;
		Vector2 operator+(const Vector2& v)const;
		Vector2 operator - (const Vector2& v)const;
		Vector2& operator+=(const Vector2& rv);
		Vector2  operator * (float v);
		Vector2   operator / (float v);
	
		//! 0 向量
		static Vector2 Zero;
	
		//! 计算两个向量的点乘
		/*!
		\param const Vector2 & v1 
		\param const Vector2 & v2 
		\return float  
		*/
		static float dot(const Vector2& v1, const Vector2& v2);
	
		//! 计算两个向量的叉乘
		/*!
		\param const Vector2 & v1 
		\param const Vector2 & v2 
		\return Vector2  
		*/
		static Vector2 cross(const Vector2& v1, const Vector2& v2);
		
		//! 计算两点之间的距离
		/*!
		\param const Vector2 & v1 
		\param const Vector2 & v2 
		\return float  
		*/
		static float distance(const Vector2& v1, const Vector2& v2);
	};
	
	
	typedef  Vector2 Position;
	typedef  Vector2 Distance;
	
	/*!
	 \brief 3D向量
	 \details
	*/
	class SGE_API Vector3
		:public DirectX::XMFLOAT3
	{
	public:
		//！默认构造
		Vector3()
			:DirectX::XMFLOAT3(.0f, .0f, .0f) {}
	
		//！参数构造
		Vector3(float x, float y, float z)
			:DirectX::XMFLOAT3(x, y, z) {}
	
		//！参数构造
		Vector3(DirectX::XMVECTOR v) { XMStoreFloat3(this, v); }
	
		//！拷贝构造
		Vector3(const Vector3& v)
			:DirectX::XMFLOAT3(v.x, v.y, v.z) {}
	
		//！类型转换
		operator DirectX::XMVECTOR() const { return XMLoadFloat3(this); }
	
		//重载运算符 
		bool operator == (const  Vector3& v);
		bool operator != (const  Vector3& v);
	
		//加 减 运算
		Vector3 operator+ (const Vector3& v);
		Vector3 operator- (const Vector3& v);
	
	protected:
	private:
	};
	
	/*!
	 \brief 4D向量
	 \details
	*/
	class SGE_API Vector4
		:public DirectX::XMFLOAT4
	{
	public:
		//！默认构造
		Vector4()
			:DirectX::XMFLOAT4(0, 0, 0, 0) {}
	
		//！参数构造
		Vector4(float x, float y, float z, float w)
			:DirectX::XMFLOAT4(x, y, z, w) {}
	
		//！参数构造
		Vector4(DirectX::XMVECTOR v) { XMStoreFloat4(this, v); }
	
		//！拷贝构造
		Vector4(const Vector4& v)
			:DirectX::XMFLOAT4(v.x, v.y, v.z, v.w) {}
		
		//！类型转换
		operator DirectX::XMVECTOR() const { return XMLoadFloat4(this); }
	
		//重载比较运算符 
		bool operator == (const  Vector4& v);
		bool operator != (const  Vector4& v);
	
		//加 减 运算
		Vector4 operator+ (const Vector4& v);
		Vector4 operator- (const Vector4& v);
	
	protected:
	private:
	};
}

#endif // MathType_h__
